<?php

use App\Http\Responses\RespCode;
use App\Http\Responses\RespString;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;

if (!function_exists('ling')) {
    /**
     * echo  "ling".
     *
     * @return void
     */
    function ling()
    {
        echo 'ling';
    }
}


if (!function_exists('cLog')) {
    /**
     * @param $message
     * @param array $context
     */
    function cLog($message, array $context = [])
    {
        Log::channel('cron-daily')->info($message, $context);
    }
}

if (!function_exists('dbLog')) {
    /**
     * @param $message
     * @param array $context
     */
    function dbLog($message, array $context = [])
    {
        Log::channel('db-daily')->info($message, $context);
    }
}

if (!function_exists('jResp')) {
    /**
     * @param string $msg
     * @param array $data
     * @return JsonResponse
     */
    function jResp(string $msg = '', array $data = [])
    {
        $info = ['code' => RespCode::SUCCESS, 'msg' => $msg ?: RespString::OPT_SUCCESS, 'data' => $data];
        return new JsonResponse($info);
    }
}

if (!function_exists('params_snake')) {
    function params_snake($data): array
    {
        $temp = [];
        foreach ($data as $key => $d) {
            $temp[Str::snake($key)] = $d;
        }
        return $temp;
    }
}

